package com.zsix.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.zsix.common.common.page.BaseController;
import com.zsix.common.common.page.PageDataTable;
import com.zsix.common.dto.controllerParams.OperLogParams;
import com.zsix.common.entity.taskAssignee.SmsEntity;
import com.zsix.common.util.ResultRes;
import com.zsix.framework.aspectj.annotation.OperLog;
import com.zsix.framework.aspectj.operate.LogConst;
import com.zsix.framework.operLog.service.OperLogService;
import com.zsix.system.service.ISmsEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/system")
public class SystemConfigController extends BaseController {
    @Autowired
    private ISmsEntityService smsEntityService;
    @Autowired
    private OperLogService operLogService;

    /**
     * 获取抄送消息列表
     * @param sms
     * @return
     */
    @OperLog(operModul = "系统参数相关" , operType = LogConst.OTHER , operDesc = "获取知会消息列表")
    @PostMapping("/getCCSmsList")
    public PageDataTable getCCSmsList(@RequestBody SmsEntity sms){
        startPage();
        List<SmsEntity> list=smsEntityService.ccSmsList(sms);
        return getDataTable(list);
    }

    /**
     * 获取消息列表
     * @param sms
     * @return
     */
    @OperLog(operModul = "系统参数相关" , operType = LogConst.OTHER , operDesc = "获取消息列表")
    @PostMapping("/getSmsList")
    public PageDataTable getSmsList(@RequestBody SmsEntity sms){
        startPage();
        List<SmsEntity> list=smsEntityService.smsList(sms);
        return getDataTable(list);
    }
    /**
     * 设置消息已读
     * @param sms
     * @return
     */
    @OperLog(operModul = "系统参数相关" , operType = LogConst.UPDATE , operDesc = "设置消息已读")
    @PostMapping("/readSms")
    public ResultRes readSms(@RequestBody SmsEntity sms){
        String msg =smsEntityService.updateState(sms);
        if(msg.equals("suess")) {
            return ResultRes.success("执行成功");
        }
        else{
            return ResultRes.error(msg);
        }
    }

    /**
     * 删除消息
     * @param sms
     * @return
     */
    @OperLog(operModul = "系统参数相关" , operType = LogConst.DELETE , operDesc = "删除消息")
    @PostMapping("/deleteSms")
    public ResultRes deleteSms(@RequestBody SmsEntity sms){
        String msg =smsEntityService.deleteSms(sms);
        if(msg.equals("suess")) {
            return ResultRes.success("执行成功");
        }
        else{
            return ResultRes.error(msg);
        }
    }

    /**
     * 查询系统操作日志
     * @param param
     * @return
     */
    @PostMapping("/operLog")
    public ResultRes operLog(@RequestBody OperLogParams param){
        return ResultRes.success(operLogService.findOperLogPage(param));
    }

    /**
     * 查询系统异常日志
     * @param param
     * @return
     */
    @PostMapping("/deleteOperLog")
    public ResultRes deleteOperLog(@RequestBody OperLogParams param){
        return ResultRes.success(operLogService.deleteOperLog(param));
    }
}
